import React from 'react'
import { RouteObject } from 'react-router-dom'
import { RouterGuard } from './guard/guard'

function LazyComponent(factory: () => Promise<{ default: any }>) {
  const Component = React.lazy(factory)
  return <Component />
}

function LazyGuardComponent(factory: () => Promise<{ default: any }>) {
  return <RouterGuard>{LazyComponent(factory)}</RouterGuard>
}

export const routes: RouteObject[] = [
  {
    path: '/demo',
    element: LazyGuardComponent(() => import('@/page/demo/demo')),
    children: [
      {
        path: 'child',
        element: LazyComponent(() => import('@/page/demo/demo-child/demo-child')),
      },
    ],
  },
]
